﻿using OF.BLL.Dish;
using OF.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OF.Web.admin
{
    public partial class dishlist : System.Web.UI.Page
    {
        DishAdmin dishadmin = new DishAdmin();
        DishCart dishcartbll = new DishCart();
        string strwhere = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        public void Bind()
        {
            if (string.IsNullOrWhiteSpace(strwhere))
                strwhere = " sellerid="+WebUtils.GetId();
            else
                strwhere += " and sellerid=" + WebUtils.GetId();
            OFPager.RecordCount = dishadmin.GetRecordCount(strwhere);
            RepDish.DataSource = dishadmin.GetListByPages(strwhere, "", OFPager.CurrentPageIndex, OFPager.PageSize);
            RepDish.DataBind();

            if (RepDish.Items.Count == 0)
                Nodata.Visible = true;
            else
                Nodata.Visible = false;
        }

        protected void Pager_PageChanged(object sender, EventArgs e)
        {
            Bind();
        }

        public string GetCartName(object cartid)
        {
            string cartname = string.Empty;
            if (cartid != null)
            {
                Model.DishCarts dishcartModel= dishcartbll.GetModel(Convert.ToInt32(cartid));
                cartname = dishcartModel.catname;
            }
            return cartname;
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            var sc = new SearcherColletion(this);
            strwhere = sc.GetSqlWhere("basic");
            OFPager.SearchCriteria = strwhere;
            Bind();
        }
    }
}